//
//  MeHeadCell.m
//  Molian
//
//  Created by 胡津 on 8/7/15.
//  Copyright (c) 2015年 xiaocan. All rights reserved.
//

#import "MeHeadCell.h"

@implementation MeHeadCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        //头像
        self.userAvatarImg = [[UIImageView alloc]init];
        self.userAvatarImg.layer.masksToBounds = YES;//开启圆角
        [self.userAvatarImg.layer setCornerRadius:3];
        [self.userAvatarImg setContentMode:UIViewContentModeScaleAspectFill];
        self.userAvatarImg.userInteractionEnabled = YES;
        [self.contentView addSubview:self.userAvatarImg];
        
        
        //名字
        self.userName = [[UILabel alloc]init];
        self.userName.textColor = [UIColor blackColor];
        self.userName.font = [UIFont fontWithName:FontName size:16];
        self.userName.lineBreakMode = NSLineBreakByTruncatingMiddle;
        [self.contentView addSubview:self.userName];
        
        self.integrityLabel = [[UILabel alloc] init];
        self.integrityLabel.backgroundColor = APPCOLOR(1);
        self.integrityLabel.layer.masksToBounds = YES;
        self.integrityLabel.layer.cornerRadius = 10;
        self.integrityLabel.textAlignment = NSTextAlignmentCenter;
        self.integrityLabel.font = kFont(12);
        self.integrityLabel.textColor = [UIColor whiteColor];
        self.integrityLabel.hidden = YES;
        [self.contentView addSubview:self.integrityLabel];
        
        self.daihao = [[UILabel alloc]init];
        self.daihao.textColor = [UIColor darkGrayColor];
        self.daihao.font = [UIFont fontWithName:FontName size:14];
        [self.contentView addSubview:self.daihao];
        self.daihao.userInteractionEnabled = NO;
        
        _icon_tag =[[UIImageView alloc]init];
        
        [self addSubview:_icon_tag];
        
    }
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    NSString *str;
    if ([MLUser currentUser].type == 0) {
        str = @"实习恋人";
    }else if ([MLUser currentUser].type == 1) {
        str = @"专属恋人";
    }else if ([MLUser currentUser].type == 2) {
        str = @"梦想恋人";
    }
    
    [_icon_tag setImage:[UIImage imageNamed:str]];

    
    CGFloat cellheigh = CGRectGetHeight(self.contentView.frame) - 20;
    self.userAvatarImg.frame = CGRectMake(10, (CGRectGetHeight(self.contentView.frame)-cellheigh)/2, cellheigh, cellheigh);
    self.userName.frame = CGRectMake(cellheigh+20, CGRectGetMidY(_userAvatarImg.frame)-20, DeviceWidth-120, 20);
    
    self.integrityLabel.frame = CGRectMake(DeviceWidth - 105, 5, 100, 20);
    
    self.daihao.frame = CGRectMake(cellheigh+20, CGRectGetMidY(_userAvatarImg.frame), DeviceWidth-120, 20);
    
    NSInteger x = [Utils LabeSizeText:self.daihao.text Font:self.daihao.font].width+CGRectGetMinX(self.daihao.frame);
    NSInteger y = CGRectGetMidY(_userAvatarImg.frame);
    _icon_tag.frame = CGRectMake(x+10.0, y+6.0, 50.0, 12.0);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
